package com.elite;

import java.io.FileInputStream;
import java.text.SimpleDateFormat;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class test3 {
    public static void main(String[] Args) {
        try {
            POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream("C:/XFSMQGF_20130903.xls"));
            HSSFWorkbook wb = new HSSFWorkbook(fs);
            HSSFSheet childSheet = wb.getSheetAt(0);   
	        int rowNum=childSheet.getLastRowNum()+1;
	        int size=rowNum-1;
	        String[][] data=new String[size][90];
	        SimpleDateFormat DateFormat=new SimpleDateFormat("yyyy-MM-dd"); 
	        System.out.println("rowNum:"+rowNum);
	        for(int j=1;j<rowNum;j++){
	        	System.out.println("j:"+j);
	        	HSSFRow row = childSheet.getRow(j);    
                int cellNum=row.getLastCellNum(); 
                for(int k=0;k<cellNum;k++){
                	HSSFCell cell=row.getCell((short) k);
            		if(cell==null){
            			data[j-1][k]="";
            		}else if(cell.getCellType()==3){
                		data[j-1][k]="";
                	}else if(cell.getCellType()==1){
                    		String a=cell.toString();
                			data[j-1][k]=cell.toString();
                	}else if(cell.getCellType()==0){
                		if(HSSFDateUtil.isCellDateFormatted(cell)){
                			data[j-1][k]= DateFormat.format(cell.getDateCellValue());
                        	if(data[j-1][k].length()>19){
                        	  data[j-1][k]= DateFormat.format(cell.getDateCellValue()).substring(0,19);
                        	}
                		}else{
                			double a=cell.getNumericCellValue();
                    		data[j-1][k]=a+"";
                		}
                	}else if(HSSFCell.CELL_TYPE_BLANK == cell.getCellType()){
                		data[j-1][k]="";
                	}
                }
	        }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
